home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / time / c / ftime < prev    next >
Text File  |  1996-11-09  |  1KB  |  62 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/time/c/RCS/ftime,v $
  4.  * $Date: 1996/10/30 21:57:16 $
  5.  * $Revision: 1.1 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: ftime,v $
  10.  * Revision 1.1  1996/10/30 21:57:16  unixlib
  11.  * Initial revision
  12.  *
  13.  ***************************************************************************/
  14.  
  15. static const char rcs_id[] = "$Id: ftime,v 1.1 1996/10/30 21:57:16 unixlib Rel $";
  16.  
  17. /* time.c.ftime.
  18.    Function implementation for <sys/timeb.h>.
  19.  
  20.    Written by Nick Burrett, 6 October 1996.  */
  21.  
  22. #include <sys/timeb.h>
  23. #include <sys/time.h>
  24. #include <errno.h>
  25.  
  26. /* Fill in timebuf with information about the current time.  */
  27.  
  28. int
  29. ftime (struct timeb *timebuf)
  30. {
  31.   int temp;
  32.   struct tm *tp;
  33.  
  34.   /* Save the errno because it could change in the forthcoming
  35.      function calls.  */
  36.   temp = errno;
  37.  
  38.   /* Reset errno so we can look for a possible error in time().  */
  39.   errno = 0;
  40.   if (time (&timebuf->time) == (time_t) -1 || errno != 0)
  41.     /* Time is not available.  */
  42.     return -1;
  43.  
  44.   /* On RISC OS we don't support milliseconds.  */
  45.   timebuf->millitm = 0;
  46.  
  47.   tp = localtime (&timebuf->time);
  48.   if (tp == NULL)
  49.     return -1;
  50.  
  51.   /* Specify if DST was used.  */
  52.   timebuf->dstflag = tp->tm_isdst;
  53.  
  54.   /* Calculate the minutes west of GMT.  */
  55.   timebuf->timezone = tp->tm_gmtoff / 60;
  56.  
  57.   /* Restore the original errno state. */
  58.   errno = temp;
  59.  
  60.   return 0;
  61. }
  62.